//Name:
//Purpose:
//Author: wjy
//Date: 2022-01-10 15:39:57
//From:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int a1, a2, a3,
        a4, a5, a6, a7,
        a8, a9, a10, a11, a12;
    int sum1, sum2, total;
    printf("Enter the first 12 digits of a UPC: ");
    scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",
          &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11, &a12);
    sum1 = a1 + a3 + a5 + a7 + a9 + a11;
    sum2 = a2 + a4 + a6 + a8 + a10;
    total = 3 * sum1 + sum2 - 1;
    total = total % 10;
    if ((9 - total) == a12)
    {
        printf("VALID\n");
    }
    else
    {
        printf("NOT VALID\n");
    }
    system("pause");
    return 0;
}